/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package yuhuibear.poat.test.util;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

/**
 * 描述数据库的。
 * 
 * @author yuhui_bear
 */
public class PoatTestSource implements DataSource {

	private String url = "jdbc:postgresql://localhost:5432/poat";
	private String user = "yuhui";
	private String password = "123";
	private String driver = "org.postgresql.Driver";

	@Override
	public String toString() {
		return user + " : " + password + " @ " + url + ", driver : "
				+ this.driver;
	}

	public void main(String[] args) throws Exception {
		System.out.println("test source : " + this.toString());
	}

	org.postgresql.ds.PGSimpleDataSource source;

	public PoatTestSource() {
		source = new org.postgresql.ds.PGSimpleDataSource();
		source.setServerName("localhost");
		source.setDatabaseName("poat");
		source.setUser(user);
		source.setPassword(password);
	}

	@Override
	public Connection getConnection() throws SQLException {
		return source.getConnection();
	}

	@Override
	public Connection getConnection(String username, String password)
			throws SQLException {
		return source.getConnection(username, password);
	}

	@Override
	public PrintWriter getLogWriter() throws SQLException {
		return source.getLogWriter();
	}

	@Override
	public void setLogWriter(PrintWriter out) throws SQLException {
		source.setLogWriter(out);
	}

	@Override
	public void setLoginTimeout(int seconds) throws SQLException {
		source.setLoginTimeout(seconds);
	}

	@Override
	public int getLoginTimeout() throws SQLException {
		return source.getLoginTimeout();
	}

	@Override
	public <T> T unwrap(Class<T> iface) throws SQLException {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public boolean isWrapperFor(Class<?> iface) throws SQLException {
		throw new UnsupportedOperationException("Not supported yet.");
	}
}
